package xw.qxypt.modules.baseinfo.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import xw.qxypt.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import xw.qxypt.modules.baseinfo.entity.LhpDataRoadDetectorEntity;
import xw.qxypt.modules.baseinfo.entity.LhpDataWeatherStationEntity;
import xw.qxypt.modules.baseinfo.service.LhpDataWeatherStationService;
import xw.qxypt.common.utils.PageUtils;
import xw.qxypt.common.utils.R;



/**
 * 
 *
 * @author xw
 * @email 
 * @date 2019-11-28 16:38:08
 */
@RestController
@RequestMapping("baseinfo/lhpdataweatherstation")
public class LhpDataWeatherStationController {
    @Autowired
    private LhpDataWeatherStationService lhpDataWeatherStationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = lhpDataWeatherStationService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("baseinfo:lhpdataweatherstation:info")
    public R info(@PathVariable("id") String id){
        LhpDataWeatherStationEntity lhpDataWeatherStation = lhpDataWeatherStationService.getById(id);

        return R.ok().put("lhpDataWeatherStation", lhpDataWeatherStation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("baseinfo:lhpdataweatherstation:save")
    public R save(@RequestBody LhpDataWeatherStationEntity lhpDataWeatherStation){
        lhpDataWeatherStationService.save(lhpDataWeatherStation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("baseinfo:lhpdataweatherstation:update")
    public R update(@RequestBody LhpDataWeatherStationEntity lhpDataWeatherStation){
        ValidatorUtils.validateEntity(lhpDataWeatherStation);
        lhpDataWeatherStationService.updateById(lhpDataWeatherStation);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("baseinfo:lhpdataweatherstation:delete")
    public R delete(@RequestBody String[] ids){
        lhpDataWeatherStationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 首页路面参数图层
     */
    @RequestMapping("/weatherStationOverlay")
    public R weatherStationOverlay() {
        List<LhpDataWeatherStationEntity> list=lhpDataWeatherStationService.weatherStationOverlay();
        return R.ok().put("data",list);
    }
    /**
     * 根据安装点获取最新一条信息 //如果无信息通过接口获取
     */
    @RequestMapping("/getDataWeatherStationByPointId/{pointId}")
    public R getDataWeatherStationByPointId(@PathVariable("pointId") String pointId){
        LhpDataWeatherStationEntity lhpDataWeatherStation = lhpDataWeatherStationService.getDataWeatherStationByPointId(pointId);

        return R.ok().put("lhpDataWeatherStation", lhpDataWeatherStation);
    }

    /**
     * 3小时数据用于凝冰详情页
     */
    @RequestMapping("/weatherStationChart/{pointId}")
    public List<LhpDataWeatherStationEntity> weatherStationChart(@PathVariable("pointId") String pointId){
        List<LhpDataWeatherStationEntity> list = lhpDataWeatherStationService.weatherStationChart(pointId);

        return list;
    }

    /**
     * 首页路面信息chart
     */
    @RequestMapping("/weatherChart")
    public R weatherChart() {
        Map map=lhpDataWeatherStationService.weatherChart();
        return R.ok().put("data",map);
    }

}
